/*
    SUSAN® - Sole of Unix Save ANything

   Copyright (C) 2006-2007 Hechzh Property
   Copyright (C) 2016-2016 Skyatlas Co. CN

   
*/
/*
 * Written by Robert Nelson, June 2006
 */
/**
 * @file
 * Implement routines to determine drive type (Windows specific).
 */

#include "include/susan.h"
#include "find.h"
#include "findlib/drivetype.h"

/**
 * These functions should be implemented for each OS
 *
 * bool Drivetype(const char *fname, char *dt, int dtlen);
 */
#if defined(HAVE_WIN32)
/* Windows */

bool Drivetype(const char* fname, char* dt, int dtlen)
{
  CHAR rootpath[4];
  UINT type;

  /*
   * Copy Drive Letter, colon, and backslash to rootpath
   */
  bstrncpy(rootpath, fname, 3);
  rootpath[3] = '\0';

  type = GetDriveType(rootpath);

  switch (type) {
    case DRIVE_REMOVABLE:
      bstrncpy(dt, "removable", dtlen);
      return true;
    case DRIVE_FIXED:
      bstrncpy(dt, "fixed", dtlen);
      return true;
    case DRIVE_REMOTE:
      bstrncpy(dt, "remote", dtlen);
      return true;
    case DRIVE_CDROM:
      bstrncpy(dt, "cdrom", dtlen);
      return true;
    case DRIVE_RAMDISK:
      bstrncpy(dt, "ramdisk", dtlen);
      return true;
    case DRIVE_UNKNOWN:
    case DRIVE_NO_ROOT_DIR:
    default:
      return false;
  }
}
/* Windows */

#else /* No recognised OS */

bool Drivetype(const char* fname, char* dt, int dtlen)
{
  Dmsg0(10, "!!! Drivetype() not implemented for this OS. !!!\n");
  return false;
}
#endif
